package com.ruoyi.zsyh.controller.applet.store;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.CommonRpc;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.zsyh.controller.applet.user.WxUserController;
import com.ruoyi.zsyh.domain.*;
import com.ruoyi.zsyh.service.*;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 扫码流程Controller
 */
@Controller
@RequestMapping("/applet/zsyh/partsQrcode")
public class ZsyhPartsQrCodeAppletController extends BaseController
{
    private Logger logger = LoggerFactory.getLogger(ZsyhPartsQrCodeAppletController.class);
    
    @Autowired
    private IZsyhPartsQrcodeService zsyhPartsQrcodeService;

    @Autowired
    private IZsyhPartsQrcodeHistoryService zsyhPartsQrcodeHistoryService;

    @Autowired
    private IZsyhPartsQrcodeInstallService zsyhPartsQrcodeInstallService;

    @Autowired
    private IZsyhPartsQrcodeApplyService zsyhPartsQrcodeApplyService;

    @Autowired
    private IZsyhUserRepairstoreService zsyhUserRepairstoreService;

    @Autowired
    private IZsyhPlatformPartsCheckService zsyhPlatformPartsCheckService;

    @Autowired
    private IZsyhPlatformUserService zsyhPlatformUserService;

    @Autowired
    private CommonRpc commonRpc;


    /**
     * 产品二维码 扫码展示
     * @return
     */
    @RequestMapping("/scanQrCodeWX")
    @ResponseBody
    public AjaxResult scanQrCodeWX(String data)throws Exception{
        logger.info("dataStr ----------------------------------- " + data);
        if(data.contains("=")){
            data = data.substring(data.lastIndexOf("=")+1,data.length());
        }
        data = data.replaceAll("[\\t\\n\\r]", "");
        Map map = zsyhPartsQrcodeService.getQrcodeInformation(data);
        if(map == null){
            try{
                if(data.length() > 30 ){
                    return AjaxResult.error("此二维码无法识别");
                }
                String qrcodeFirst = data.substring(0,19);//此批二维码的相同部分
                int qrcodeAfter = Integer.valueOf(data.substring(19,30));//二维码的后边自增部分
                //查询二维码是否存在
                ZsyhPartsQrcodeHistory history = zsyhPartsQrcodeHistoryService.getQrCodeTrue(qrcodeFirst, qrcodeAfter);
                if(history == null){
                    return AjaxResult.error("此二维码无法识别");
                }
                map = zsyhPartsQrcodeService.getQrcodeInformationByQrCodeFirst(qrcodeFirst);
                if(map == null){
                    return AjaxResult.error("此二维码无法识别");
                }
            }catch (Exception e){
                e.printStackTrace();
                return AjaxResult.error("此二维码无法识别");
            }
        }
        String codeNum = data.substring(16,19) + data.substring(25,30);
        map.put("codeNum", codeNum);//编码值
        map.put("qrcode", data);//编码值
        Date grantsPeriod = (Date)map.get("grantsPeriod");
        String attributeWarranty = String.valueOf(map.get("attributeWarranty"));
        if(EmptyUtils.isEmpty(grantsPeriod) && EmptyUtils.isNotEmpty(attributeWarranty)){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化对象
            Calendar calendar = Calendar.getInstance();//日历对象
            calendar.setTime(new Date());//设置当前日期
            calendar.add(Calendar.MONTH, Integer.valueOf(attributeWarranty));
            grantsPeriod = calendar.getTime();
            map.put("grantsPeriod", sdf.format(grantsPeriod));//编码值
        }
        //二维码当前状态 0未使用 1保障中 2申请中 3通过质保申请 4驳回质保申请 5已过期
        map.put("qrcodeType", "0");
        //状态 0待处理，1市县已鉴定，2市县已驳回，3大区已鉴定，4大区已驳回，5平台已审核，6已核销 7已拨款
        String applyStatus = String.valueOf(map.get("applyStatus"));;
        Date date = new Date();
        if(EmptyUtils.isNotEmpty(map.get("installImages"))){
            //2安装图片非空，已安装，请勿重复安装
            map.put("qrcodeType", "1");
        }
        if(EmptyUtils.isNotEmpty(map.get("faultImages"))){
            //申请图片非空，已申请，请勿重复申请
            map.put("qrcodeType", "2");
        }
        if(EmptyUtils.isNotEmpty(applyStatus)){
            switch (applyStatus){
                case "0":map.put("qrcodeType", "2");break;
                case "1":map.put("qrcodeType", "2");break;
                case "2":map.put("qrcodeType", "4");break;
                case "3":map.put("qrcodeType", "2");break;
                case "4":map.put("qrcodeType", "4");break;
                case "5":map.put("qrcodeType", "3");break;
                case "6":map.put("qrcodeType", "3");break;
                case "7":map.put("qrcodeType", "3");break;
            }

        }else {
            if(EmptyUtils.isNotEmpty(map.get("installImages"))){
                long dateTime = date.getTime();
                int warrantyPeriod = Integer.valueOf(String.valueOf(map.get("warrantyPeriod")));
                Date deadlineDate = (Date)map.get("installTime"); //安装日期
                Calendar calendar = Calendar.getInstance();//日历对象
                calendar.setTime(deadlineDate);//设置当前日期
                calendar.add(Calendar.MONTH, warrantyPeriod);
                long time = calendar.getTime().getTime();
                if(dateTime > time){
                    //6二维码已过补助金质保有效期
                    map.put("qrcodeType", "6");
                }
            }
        }

        return AjaxResult.success("获取成功", map);
    }


    /**
     * 小程序 扫码申请，扫码安装 根据二维码获取产品信息，扫码
     * @param type 1扫码安装 2扫码申请
     * @return
     */
    @RequestMapping("/scanQrCode")
    @ResponseBody
    public AjaxResult scanQrCode(String data, String userId, String type)throws Exception{
        ZsyhPlatformUser user = zsyhPlatformUserService.selectZsyhPlatformUserById(userId);
        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        logger.info("dataStr ----------------------------------- " + data);
        if(data.contains("=")){
            data = data.substring(data.lastIndexOf("=")+1,data.length());
        }
        data = data.replaceAll("[\\t\\n\\r]", "");
        Map map = zsyhPartsQrcodeService.getQrcodeInformation(data);
        if(map == null){
            try{
                if(data.length() > 30 ){
                    return AjaxResult.error("此二维码无法识别");
                }
                String qrcodeFirst = data.substring(0,19);//此批二维码的相同部分
                int qrcodeAfter = Integer.valueOf(data.substring(19,30));//二维码的后边自增部分
                //查询二维码是否存在
                ZsyhPartsQrcodeHistory history = zsyhPartsQrcodeHistoryService.getQrCodeTrue(qrcodeFirst, qrcodeAfter);
                if(history == null){
                    return AjaxResult.error("此二维码无法识别");
                }
                map = zsyhPartsQrcodeService.getQrcodeInformationByQrCodeFirst(qrcodeFirst);
                if(map == null){
                    return AjaxResult.error("此二维码无法识别");
                }
            }catch (Exception e){
                e.printStackTrace();
                return AjaxResult.error("此二维码无法识别");
            }
        }
        String codeNum = data.substring(16,19) + data.substring(25,30);
        map.put("codeNum", codeNum);//编码值
        map.put("qrcode", data);
        Date grantsPeriod = (Date)map.get("grantsPeriod");

        String attributeWarranty = String.valueOf(map.get("attributeWarranty"));
        if(EmptyUtils.isEmpty(grantsPeriod)  && EmptyUtils.isNotEmpty(attributeWarranty)){
            Date installTime = (Date)map.get("installTime");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化对象
            Calendar calendar = Calendar.getInstance();//日历对象
            if(EmptyUtils.isEmpty(installTime)){
                calendar.setTime(new Date());//设置当前日期
            }else{
                calendar.setTime(installTime);//设置当前日期
            }
            calendar.add(Calendar.MONTH, Integer.valueOf(attributeWarranty));
            grantsPeriod = calendar.getTime();
            map.put("grantsPeriod", sdf.format(grantsPeriod));
        }
        //二维码当前状态 0正常 1二维码已过有效期 2二维码已安装，请勿重复安装
        // 3暂未安装，无法申请补助金 4不是安装的，不能申请 5已申请，请勿重复申请 6已过期，不能申请
        map.put("qrcodeType", "0");
        Date date = new Date();
        long dateTime = date.getTime();
        if("1".equals(type)){//1扫码安装，判断有没有过期，是不是已经安装了
            Date deadlineDate = (Date)map.get("deadlineDate");
            long deadlineDateTime = deadlineDate.getTime();
            if(dateTime > deadlineDateTime){
                //1二维码已过有效期
                map.put("qrcodeType", "1");
                map.put("grantsPeriod", deadlineDate);
            }else if(EmptyUtils.isNotEmpty(map.get("installImages"))){
                //2安装图片非空，已安装，请勿重复安装
                map.put("qrcodeType", "2");
            }
        }
        if("2".equals(type)){//2扫码申请，判断是否已申请
            boolean isTure = true;
            if(EmptyUtils.isEmpty(map.get("installImages"))){
                //安装图片为空，暂未安装，无法申请补助金
                map.put("qrcodeType", "3");
                isTure = false;
            }
            if(isTure && !repairId.equals(map.get("repairId"))){
                //判断用户id，是不是扫码安装的那个师傅。如果不是提示不是你安装的，不能申请
                map.put("qrcodeType", "4");
                isTure = false;
                String installRepairPhone = String.valueOf(map.get("installRepairPhone"));
                if(user.getUserPhone().equals(installRepairPhone)){
                    map.put("qrcodeType", "0");
                    isTure = true;
                }
            }
            if(isTure && EmptyUtils.isNotEmpty(map.get("faultImages"))){
                //申请图片非空，已申请，请勿重复申请
                map.put("qrcodeType", "5");
                isTure = false;
            }
            if(isTure){
                int warrantyPeriod = Integer.valueOf(String.valueOf(map.get("warrantyPeriod")));
                Date deadlineDate = (Date)map.get("installTime"); //安装日期
                Calendar calendar = Calendar.getInstance();//日历对象
                calendar.setTime(deadlineDate);//设置当前日期
                calendar.add(Calendar.MONTH, warrantyPeriod);
                long time = calendar.getTime().getTime();
                if(dateTime > time){
                    //6二维码已过补助金质保有效期
                    map.put("qrcodeType", "6");
                }
            }

        }
        return AjaxResult.success("获取成功", map);
    }

    /**
     * 扫码安装  提交安装
     * @param qrcodeId
     * @param userId
     * @param installImages
     * @return
     * @throws Exception
     */
    @RepeatSubmit
    @RequestMapping("/scanQrCodeInstall")
    @ResponseBody
    @Transactional
    public AjaxResult scanQrCodeInstall(String qrcodeId, String userId, String installImages)throws Exception{
        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        ZsyhPartsQrcode qrcode = zsyhPartsQrcodeService.selectZsyhPartsQrcodeById(qrcodeId);
        if(qrcode == null){
            String qrcodeFirst = qrcodeId.substring(0,19);//此批二维码的相同部分
            //int qrcodeAfter = Integer.valueOf(qrcodeId.substring(19,30));//二维码的后边自增部分
            qrcode = zsyhPartsQrcodeService.selectZsyhPartsQrcodeByQrCodeFirst(qrcodeFirst);

            ZsyhPartsQrcode qrcode1 = new ZsyhPartsQrcode();
            qrcode1.setQrcodeId(qrcodeId);
            qrcode1.setPartsId(qrcode.getPartsId());
            qrcode1.setAttributeId(qrcode.getAttributeId());
            qrcode1.setProductionDate(qrcode.getProductionDate());
            qrcode1.setDeadlineDate(qrcode.getDeadlineDate());
            qrcode1.setPayPrice(qrcode.getPayPrice());
            zsyhPartsQrcodeService.insertZsyhPartsQrcode(qrcode1);

        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化对象
        ZsyhPartsQrcodeInstall install = new ZsyhPartsQrcodeInstall();
        install.setRepairName(store.getStoreName());
        install.setRepairPhone(store.getStorePhone());

        install.setId(IdWorker.getId());
        install.setAttributeId(qrcode.getAttributeId());
        install.setPartsId(qrcode.getPartsId());
        install.setInstallImages(installImages);
        install.setInstallPeriod(sdf.format(qrcode.getProductionDate()) + " 至 " + sdf.format(qrcode.getDeadlineDate()));
        install.setRepairId(repairId);
        install.setQrcodeId(qrcodeId);
        install.setQualityPeriod(qrcode.getAttributeFreeWarranty());
        install.setWarrantyPeriod(qrcode.getAttributeWarranty());
        install.setPayPrice(qrcode.getPayPrice().longValue());

        String warrantyPeriod = qrcode.getAttributeWarranty();
        Calendar calendar = Calendar.getInstance();//日历对象
        calendar.setTime(new Date());//设置当前日期
        calendar.add(Calendar.MONTH, Integer.valueOf(warrantyPeriod));
        Date grantsPeriod = calendar.getTime();
        install.setGrantsPeriod(grantsPeriod);//计算申请补助金截至日期

        zsyhPartsQrcodeInstallService.insertZsyhPartsQrcodeInstall(install);

        return AjaxResult.success("操作成功");
    }


    /**
     * 扫码申请 提交申请
     * @param qrcodeId
     * @param userId
     * @param faultImages
     * @return
     * @throws Exception
     */
    @RepeatSubmit
    @RequestMapping("/scanQrCodeApply")
    @ResponseBody
    @Transactional
    public synchronized AjaxResult scanQrCodeApply(String qrcodeId, String userId, String faultImages, String faultDetails, String lat, String lon)throws Exception{
        ZsyhPartsQrcodeApply _apply = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyByQrCodeId(qrcodeId);
        if(_apply != null){
            return error("已申请，请勿重复提交申请");
        }

        ZsyhPlatformUser user = zsyhPlatformUserService.selectZsyhPlatformUserById(userId);
        String phone = user.getUserPhone();

        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        ZsyhPartsQrcode qrcode = zsyhPartsQrcodeService.selectZsyhPartsQrcodeById(qrcodeId);

        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setId(IdWorker.getId());
        apply.setAttributeId(qrcode.getAttributeId());
        apply.setPartsId(qrcode.getPartsId());
        apply.setFactoryId(qrcode.getFactoryId());
        apply.setRepairId(repairId);
        apply.setQrcodeId(qrcodeId);
        apply.setFaultImages(faultImages);
        apply.setFaultDetails(faultDetails);
        apply.setApplyChannel("1");
        apply.setApplyStatus("0");
        apply.setStorePhone(store.getStorePhone());
        apply.setStoreName(store.getStoreName());


        zsyhPartsQrcodeApplyService.insertZsyhPartsQrcodeApply(apply);


        ZsyhUserRepairstore userPartsstore = new ZsyhUserRepairstore();
        userPartsstore.setLat(lat);
        userPartsstore.setLon(lon);
        userPartsstore.setStoreState("2");//审核通过的店铺
        userPartsstore.setIsAppraisal("1");//有配件鉴定权的店铺
        Map map = new HashedMap();
        map.put("beginPos", 0);
        map.put("pageSize", 1);
        map.put("juli", "小于100");
        map.put("juliSort", "最近");
        userPartsstore.setParams(map);

        List<ZsyhUserRepairstore> list = zsyhUserRepairstoreService.selectZsyhUserRepairstoreListApplet(userPartsstore);
        commonRpc.sendSmsApplyGrants(phone);//申请成功，发送短信提醒
        if(list.size() > 0){
            userPartsstore = list.get(0);
            return AjaxResult.success("操作成功", userPartsstore.getStorePhone());
        }else{
            return AjaxResult.success("操作成功", "4009615811");
        }

    }



    /**
     * 获取补助金申请记录
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping("/getQrCodeApplyList")
    @ResponseBody
    @Transactional
    public AjaxResult getQrCodeApplyList(String userId, String pageNum, String pageSize)throws Exception{
        ZsyhPlatformUser user = zsyhPlatformUserService.selectZsyhPlatformUserById(userId);
        String phone = user.getUserPhone();

        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
//        apply.setRepairId(repairId);
        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        map.put("repairId", repairId);
        map.put("repairPhone", phone);
        apply.setParams(map);


        List<ZsyhPartsQrcodeApply> list = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyList(apply);

        return AjaxResult.success("成功", list);
    }

    /**
     * 获取补助金申请详情
     * @return
     * @throws Exception
     */
    @RequestMapping("/getQrCodeApplyDetails")
    @ResponseBody
    @Transactional
    public AjaxResult getQrCodeApplyDetails(String applyId)throws Exception{
        ZsyhPartsQrcodeApply apply = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyById(applyId);
        String codeNum = apply.getQrcodeId().substring(16,19) + apply.getQrcodeId().substring(25,30);
        apply.setCodeNum(codeNum);//编码值
        String grantsPeriod = apply.getGrantsPeriod();
        String attributeWarranty = apply.getWarrantyPeriod();

        if(EmptyUtils.isEmpty(grantsPeriod) && EmptyUtils.isNotEmpty(attributeWarranty)){
            String installTime = apply.getInstallTime();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化对象
            Calendar calendar = Calendar.getInstance();//日历对象
            calendar.setTime(new Date());//设置当前日期
            calendar.add(Calendar.MONTH, Integer.valueOf(attributeWarranty));
            grantsPeriod = sdf.format(calendar.getTime());
            apply.setGrantsPeriod(grantsPeriod);
        }

        return AjaxResult.success("成功", apply);
    }


    /**
     * 提取补助金，生成唯一提取码
     * @param applyId
     * @return
     * @throws Exception
     */
    @RequestMapping("/extractQrCodeGrants")
    @ResponseBody
    @Transactional
    public AjaxResult extractQrCodeGrants(String applyId)throws Exception{

        ZsyhPartsQrcodeApply apply1 = new ZsyhPartsQrcodeApply();
        apply1.setId(applyId);
        apply1.setExtractionCode(StringUtils.getRandomCode());
        zsyhPartsQrcodeApplyService.updateZsyhPartsQrcodeApply(apply1);

        ZsyhPartsQrcodeApply apply = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyById(applyId);
        String codeNum = apply.getQrcodeId().substring(16,19) + apply.getQrcodeId().substring(25,30);
        apply.setCodeNum(codeNum);//编码值
        apply.setExtractionCode(apply1.getExtractionCode());

        return AjaxResult.success("成功", apply);
    }


    /**
     * 扫码鉴定
     * @return
     */
    @RequestMapping("/scanQrCodeAppraisal")
    @ResponseBody
    public AjaxResult scanQrCodeAppraisal(String data, String userId)throws Exception{
        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();

        logger.info("dataStr ----------------------------------- " + data);
        if(data.contains("=")){
            data = data.substring(data.lastIndexOf("=")+1,data.length());
        }
        data = data.replaceAll("[\\t\\n\\r]", "");
        ZsyhPartsQrcodeApply apply = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyByQrCodeId(data);
        if(apply == null){
            return AjaxResult.error("此产品二维码暂未申请补助金");
        }
        String partsId = apply.getPartsId();

        ZsyhPlatformPartsCheck check = new ZsyhPlatformPartsCheck();
        check.setPartsId(partsId);
        check.setStoreId(repairId);
        List<ZsyhPlatformPartsCheck> list = zsyhPlatformPartsCheckService.selectZsyhPlatformPartsCheckList(check);
        if(list.size() == 0){
            return AjaxResult.error("您没有此商品的鉴定权限，请联系大区会长");
        }

        String codeNum = data.substring(16,19) + data.substring(25,30);
        apply.setCodeNum(codeNum);
        return AjaxResult.success("获取成功", apply);
    }


    /**
     * 提交产品鉴定结果
     * @param applyId
     * @param userId
     * @param applyStatus 1市县已通过 2市县已驳回
     * @param auditContent
     * @return
     * @throws Exception
     */
    @RequestMapping("/saveQrCodeAppraisal")
    @ResponseBody
    @Transactional
    public AjaxResult saveQrCodeAppraisal(String applyId, String userId, String applyStatus,String auditContent)throws Exception{
        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        String agentId = store.getAgentId();

        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setId(applyId);
        apply.setStoreId(repairId);
        apply.setAgentId(agentId);
        apply.setApplyStatus(applyStatus);
        apply.setAuditContent(auditContent);
        apply.setAuditTime(new Date());
        zsyhPartsQrcodeApplyService.updateZsyhPartsQrcodeApply(apply);

        return AjaxResult.success("成功", apply);
    }


    /**
     * 获取补助金鉴定记录
     * @param userId
     * @return
     * @throws Exception
     */
    @RequestMapping("/getQrCodeAppraisalList")
    @ResponseBody
    @Transactional
    public AjaxResult getQrCodeAppraisalList(String userId, String pageNum, String pageSize)throws Exception{
        ZsyhUserRepairstore store = zsyhUserRepairstoreService.selectZsyhUserRepairstoreByUserId(userId);
        String repairId = store.getId();
        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setStoreId(repairId);
        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        apply.setParams(map);


        List<ZsyhPartsQrcodeApply> list = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyList(apply);

        return AjaxResult.success("成功", list);
    }


    /**
     * 会长获取补助金申请记录（市县已经审核通过的）
     * @param status 1未处理 2已处理
     * @return
     * @throws Exception
     */
    @RequestMapping("/getQrCodeApplyListByAgentId")
    @ResponseBody
    @Transactional
    public AjaxResult getQrCodeApplyListByAgentId(String agentId, String status, String pageNum, String pageSize)throws Exception{
        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setAgentId(agentId);
        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        if("1".equals(status)){
            apply.setApplyStatus(status);
        }else{
            map.put("status", "2");
        }
        apply.setParams(map);
        List<ZsyhPartsQrcodeApply> list = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyList(apply);

//        return AjaxResult.success("成功", list);
        return AjaxResult.success("成功", new ArrayList<>());
    }


    /**
     * 会长鉴定
     * @param applyId
     * @param agentId
     * @param applyStatus
     * @param agentContent
     * @return
     * @throws Exception
     */
    @RequestMapping("/saveQrCodeAppraisalByAgentId")
    @ResponseBody
    @Transactional
    public AjaxResult saveQrCodeAppraisalByAgentId(String applyId, String agentId, String applyStatus,String agentContent)throws Exception{

        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setId(applyId);
        apply.setAgentId(agentId);
        apply.setApplyStatus(applyStatus);
        apply.setAgentContent(agentContent);
        apply.setAgentTime(new Date());
        zsyhPartsQrcodeApplyService.updateZsyhPartsQrcodeApply(apply);

        return AjaxResult.success("成功", apply);
    }


    /**
     * 厂家查看补助金列表
     * @param factoryId
     * @param status 状态 1处理中 5已审核 7已赔付
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping("/getQrCodeApplyListByFactoryId")
    @ResponseBody
    @Transactional
    public AjaxResult getQrCodeApplyListByFactoryId(String factoryId, String status, String pageNum, String pageSize)throws Exception{
        ZsyhPartsQrcodeApply apply = new ZsyhPartsQrcodeApply();
        apply.setFactoryId(factoryId);
        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        map.put("statusFactory", status);
        apply.setParams(map);
        List<ZsyhPartsQrcodeApply> list = zsyhPartsQrcodeApplyService.selectZsyhPartsQrcodeApplyList(apply);

        return AjaxResult.success("成功", list);
    }
}
